﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBToExcel.Code
{
    public class Tools
    {
        public int Random()
        {
            return new Random(5).Next();
        }

        /// <summary>
        /// 获取id
        /// </summary>
        /// <returns></returns>
        public string GetId()
        {
            return IdWorker.Instance().nextId().ToString();
        }

        /// <summary>
        /// 金额转大写
        /// </summary>
        /// <param name="money"></param>
        /// <returns></returns>
        public string MoneyToUpper(string money) {

            return MoneyToUpperUtils.Convert(money);
        }

       /// <summary>
       /// 时间格式化
       /// </summary>
       /// <param name="value"></param>
       /// <returns></returns>       
        public string DateFormat(string value,string pattern=null) {
            if (string.IsNullOrEmpty(value))
            {
                return string.Empty;
            }

            DateTime time;
            if (!DateTime.TryParse(value,out time))
            {
                return string.Empty;
            }

            pattern = pattern == null ? "yyyy-MM-dd HH:mm:ss" : pattern;
            return time.ToString(pattern);
        }

       /// <summary>
       /// 分割字符串
       /// </summary>
       /// <param name="text"></param>
       /// <param name="pattern"></param>
       /// <returns></returns>       
        public string[] Split(string  text,string pattern) {
            if (string.IsNullOrEmpty(text))
            {
                return null;
            }

         return   text.Split(new string[] { pattern }, int.MaxValue, StringSplitOptions.None);
        }
    }
}
